﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace r4u.data.access.layer.RECRUIT
{
    public class SkillDAO
    {
        public bool Insert(VACANCY_SKILL skill)
        {
            try
            {
                using (var context = new r4uEntities())
                {
                    context.VACANCY_SKILL.Add(skill);
                    context.SaveChanges();
                    return true;
                }
            }
            catch (Exception e)
            {
                return false;
            }
        }


        public bool Delete(string vacancy_id, string skill_id)
        {
            using (var context = new r4uEntities())
            {
                try
                {
                    VACANCY_SKILL vs = context.VACANCY_SKILL.FirstOrDefault(x => x.vacancy_id.Equals(vacancy_id) && x.skill_id.Equals(skill_id));
                    context.VACANCY_SKILL.Remove(vs);
                    context.SaveChanges();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }


        public VACANCY_SKILL[] List(string vacancy_id)
        {
            using (var context = new r4uEntities())
            {
                VACANCY v = context.VACANCies.Include("VACANCY_SKILL").FirstOrDefault(x => x.vacancy_id.Equals(vacancy_id));

                return v.VACANCY_SKILL.Cast<VACANCY_SKILL>().ToList().ToArray();
            }
        }
    }
}